﻿var currentPage1 = 1; // 当前页
var pageSize1 = 15; // 每页显示多少条
var pageall1 = 0; // 总页数
var total1 = 0; // 总记录数

var currentPage2 = 1; // 当前页
var pageSize2 = 15; // 每页显示多少条
var pageall2 = 0; // 总页数
var total2 = 0; // 总记录数

var ftype = document.getElementById('hidftype').value;
var deptid = document.getElementById('hiddeptid').value;

var j = 1;

window.onload = function wonload() {
    Rentlist(currentPage2);
    ForSalelist(currentPage1);
   
}
//第二个查询
function ForSalelist(currentPage1) {
    var adddate1 = document.getElementById('Text1').value;
    var adddate2 = document.getElementById('Text2').value;
    var temp = document.getElementsByName("rd1");
    var rd1value = '';
    for (i = 0; i < temp.length; i++) {

        //遍历Radio

        if (temp[i].checked) {
            rd1value = temp[i].value;
        }
    }
    var type = '带看租房'; //带看售房 带看租房

    document.getElementById('divtd1').innerHTML = "<div><img src=\"../../images/loading.gif\" /></div>";

    var datawhere = '';
    datawhere = "&type=" + escape(type) + "&page=" + currentPage1 + "&pagesize=" + pageSize1 + "";

    $.ajax({
        type: "POST",
        url: "../AjaxServer.aspx",
        dataType: 'json',
        data: "alt=ForSaleList&rdvalue=" + escape(rd1value) + "&deptid=" + deptid + "&startTime=" + escape(adddate1) + "&EndTime=" + escape(adddate2) + "" + datawhere + "",
        processData: false,
        timeout: '10000',
        success: function(json) {
            divlist(json);
            //ForSalelist('带看售房', j, currentPage2);
            //j++;


        },
        error: function() {
            document.getElementById('divtd1').innerHTML = "系统繁忙";
        }

    });

}

//第一个查询
function Rentlist(currentPage2) {
    var adddate1 = document.getElementById('Text3').value;
    var adddate2 = document.getElementById('Text4').value;
    var depttype = document.getElementById('hiddepttype').value;
    
    var type = '带看售房'; //带看售房 带看租房
    var temp = document.getElementsByName("rd2");
    var rd1value = '';
    for (i = 0; i < temp.length; i++) {

        //遍历Radio

        if (temp[i].checked) {
            rd1value = temp[i].value;
        }
    }
    document.getElementById('divtd2').innerHTML = "<div><img src=\"../../images/loading.gif\" /></div>";

    var datawhere = '';

    if (type == '带看租房') {
        datawhere = "&type=" + escape(type) + "&page=" + currentPage1 + "&pagesize=" + pageSize1 + "";
    }
    else {
        datawhere = "&type=" + escape(type) + "&page=" + currentPage2 + "&pagesize=" + pageSize2 + "";
    }

    $.ajax({
        type: "POST",
        url: "../AjaxServer.aspx",
        dataType: 'json',
        data: "alt=ForSaleList&rdvalue=" + escape(rd1value) + "&hiddepttype=" + depttype + "&deptid=" + deptid + "&startTime=" + escape(adddate1) + "&EndTime=" + escape(adddate2) + "" + datawhere + "",
        processData: false,
        timeout: '10000',
        success: function(json) {
            divRent(json);
            //ForSalelist('带看售房', j, currentPage2);
            //j++;

        },
        error: function() {
            document.getElementById('divtd2').innerHTML = "系统繁忙";
        }

    });

}

//第一个查询
function divRent(response) {
    //var json = eval("(" + response + ")");
    var json = response;
    var record = json.record;
    var page = json.page;
    var depttype = document.getElementById('hiddepttype').value;
    currentPage2 = page.currentpage;
    pageall2 = parseInt(page.pageall);
    total2 = page.total;

    if (record == null || record.length == 0) {
        $("#divtd2").html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>");
        return;
    }
    $("#divtd2").html(""); // 显示列表
    var spancount=0;
    var arr = [];
    arr.push("<table  border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce' class=\"table1\" valign='top' >");
    arr.push("<tr bgcolor=\"#353c44\" >");
    arr.push("<td   style='text-align: center;background-color: #d3eaef;width:100px;'  >");
    arr.push("<div >" + page.rdvalue + "</div>");
    arr.push("</td>");
    arr.push("<td   style='text-align: center;background-color: #d3eaef;width:60px'>");
    arr.push("<div >查看次数</div>");
    arr.push("</td>");
    if (depttype != "") {
        arr.push("<td   style='text-align: center;background-color: #d3eaef;width:60px'>");
        arr.push("<div >总看</div>");
        arr.push("</td>");
    }
    arr.push("</tr>");
    for (var i = 0; i < record.length; i++) {

        if (i % 2 == 0)
            arr.push("<tr bgcolor='#FFFFFF'>");
        else
            arr.push("<tr bgcolor='#EEEDED'>");
        arr.push("<td height='20' class='STYLE6'  style='text-align: center;'>");

        arr.push("<a onclick=\"onshowpage2(" + record[i].eid + ",'带看售房','" + record[i].ename + "')\">" + record[i].ename + "</a>");
       
        arr.push("</td>");
        arr.push("<td height='20' class='STYLE6'>");
        //                if (page.ftype == '带看租房') {
        //                    arr.push(record[i].totalprice);
        //                }
        //                else {
        //                    arr.push(record[i].leaseprice);
        //                }
        arr.push(record[i].count);
        spancount += parseFloat(record[i].count);
        arr.push("</td>"); if (depttype != "") {
        arr.push("<td height='20' class='STYLE6'  style='text-align: center;'>");
        
            arr.push(" <span style='color:red'>" + record[i].allcount + "次</span>");
         arr.push("</td>");}
        arr.push("</tr>");
    }
    arr.push("</table>");
    //            arr.push("<div id=\"div2Page\" ></div>");
    document.getElementById('span1').innerHTML = "(总数："+spancount+")";
    document.getElementById('divtd2').innerHTML = arr.join('');
    //            $("#div2Page").html(""); // 清空

    //            if (pageall1 > 1) {
    //                var pageHtml = LexunJS.showPage3(currentPage2, pageall2, "Rentlist", total2); // 分页
    //                $("#div2Page").html(pageHtml);
    //            }

}
//第二个查询
function divlist(response) {
    //var json = eval("(" + response + ")");
    var json = response;
    var record = json.record;
    var page = json.page;
    var spancount=0;
    currentPage1 = page.currentpage;
    pageall1 = parseInt(page.pageall);
    total1 = page.total;

    if (record == null || record.length == 0) {
        $("#divtd1").html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>");
        return;
    }
    $("#divtd1").html(""); // 显示列表

    var arr = [];
    arr.push("<table  border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce' class=\"table1\" valign='top' >");
    arr.push("<tr bgcolor=\"#353c44\" >");
    arr.push("<td   style='text-align: center;background-color: #d3eaef;width:100px;'  >");
    arr.push("<div >" + page.rdvalue + "</div>");
    arr.push("</td>");
    arr.push("<td   style='text-align: center;background-color: #d3eaef;width:60px'>");
    arr.push("<div >查看次数</div>");
    arr.push("</td>");

    arr.push("</tr>");

    for (var i = 0; i < record.length; i++) {

        if (i % 2 == 0)
            arr.push("<tr bgcolor='#FFFFFF'>");
        else
            arr.push("<tr bgcolor='#EEEDED'>");
        arr.push("<td height='20' class='STYLE6'  style='text-align: center;'>");

        arr.push("<a onclick=\"onshowpage1(" + record[i].eid + ",'带看租房','" + record[i].ename + "')\">" + record[i].ename + "</a>");

        arr.push("</td>");


        arr.push("<td height='20' class='STYLE6'>");
        if (page.ftype == '带看租房') {
            arr.push(record[i].count);
        }
        spancount += parseFloat(record[i].count);
        arr.push("</td>");
        arr.push("</tr>");



    }
    arr.push("</table>");
    arr.push("<div id=\"div1Page\" ></div>");
    document.getElementById('span2').innerHTML = "(总数：" + spancount + ")";
    document.getElementById('divtd1').innerHTML = arr.join('');
    //            $("#div1Page").html(""); // 清空
    //            if (page.ftype == '带看租房') {
    //                if (pageall1 > 1) {
    //                    var pageHtml = LexunJS.showPage3(currentPage1, pageall1, "ForSalelist", total1); // 分页
    //                    $("#div1Page").html(pageHtml);
    //                }
    //            }
    //            else {
    //                if (pageall2 > 1) {
    //                    var pageHtml = LexunJS.showPage2(currentPage, pageall2, "ForSalelist"); // 分页
    //                    $("#div" + jnum + "Page").html(pageHtml);
    //                }
    //            }
}

function onshowpage1(eid, obj, objname) {
    var adddate1 = document.getElementById('Text1').value;
    var adddate2 = document.getElementById('Text1').value;
    var path = "&deptid=" + deptid + "&addDate2=" + escape(adddate2) + "" + "&addDate1=" + escape(adddate1) + "&eid=" + eid + "&housingname=" + objname + "";
    var typeName = "../../AM/CustomerFollowList.aspx?ftype=" + escape("带看租房") + "" + path + "";

    self.parent.closeTab(objname + '' + obj);
    self.parent.addTab(objname + '' + obj, typeName, 'icon-nav');
}
function onshowpage2(eid, obj, objname) {
    var adddate1 = document.getElementById('Text3').value;
    var adddate2 = document.getElementById('Text4').value;
    var path = "&deptid=" + deptid + "&addDate2=" + escape(adddate2) + "" + "&addDate1=" + escape(adddate1) + "&eid=" + eid + "&housingname=" + objname + "";
    var typeName = "../../AM/CustomerFollowList.aspx?ftype=" + escape("带看售房") + "" + path + "";

    self.parent.closeTab(objname + '' + obj);
    self.parent.addTab(objname + '' + obj, typeName, 'icon-nav');
}